﻿//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Mapping Application Block
//===============================================================================

using System;
using System.Collections.Generic;
using EntLibContrib.Query;

namespace EntLibContrib.Mapping.QuickStart.DomainObjects
{
	[SuperMapper(Name = "Owner Mapper", TypeColumnValue = "M")]
	public class MachineOwner : Owner
	{
		private Guid machineId;
		private Machine machine;

		[Map()]
		public Guid MachineId
		{
			get { return machineId; }
			set { machineId = value; }
		}

		public Machine Machine
		{
			get
			{
				if (machine == null)
				{
					if (machineId != Guid.Empty)
					{
						IDictionary<string, object> parameters = new Dictionary<string, object>();
						parameters.Add("Id", machineId);
						machine = MapperFactory.CreateMapper("Machine Mapper").ToDomainObject<Machine>(QueryFactory.CreateQuery("Read Machine By Id").ExecuteForRead(parameters));
					}
				}

				return machine;
			}
		}

		public override string Name
		{
			get { return Machine.Name; }
		}

		public MachineOwner()
		{ }
	}
}
